package cn.techwis.service;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.techwis.common.WxApi;
import cn.techwis.vo.InItVO;
import cn.techwis.vo.PayCloseVO;
import cn.techwis.util.WxHttpUtil;

/**
 * 关闭订单
 */
public class PayCloseSerive extends Tservice {

    /**
     * 关闭订单
     * true 成功
     * 非true 失败
     *
     * @param payCloseVO
     */
    public static Boolean closeOrder(PayCloseVO payCloseVO, InItVO inItVO) {
        validateObject(payCloseVO, PayCloseVO.PayClose.class, inItVO);
        String format = StrUtil.format(WxApi.payClose.CLOSEORDER, payCloseVO.getOut_trade_no());
        payCloseVO.setOut_trade_no(null);
        JSONObject jsonObject = WxHttpUtil.requestPost("关闭订单", format, payCloseVO, inItVO.getPrivateKeyFileName(), payCloseVO.getMchid(), inItVO.getSerialNo());
        return closeResult(jsonObject);
    }

    public static void main(String[] args) {
        PayCloseVO payCloseVO = new PayCloseVO();
        payCloseVO.setMchid("1505026761");
        payCloseVO.setOut_trade_no("1217752501201407033233368018");
        InItVO inItVO = new InItVO();
        inItVO.setPrivateKeyFileName("C:\\Users\\yando\\Desktop\\apiclient_key.pem");
        inItVO.setSerialNo("71B1200AE00607AA44A2EC99DB14387CF266C354");
        inItVO.setMchId("1505026761");
        closeOrder(payCloseVO, inItVO);
    }
}
